#include "common/sketchbook.hpp"

float back_and_forth(float x)
{
	x = 1 - motion::cubic_curve(1-x);
	return cos(x*common::tau) * (1-x);
}

float forth_and_back(float x)
{
	x = 1 - motion::cubic_curve(1-x);
	return sin(x*common::tau) * (1-x);
}

constexpr auto point_size = float2::one(10);
float2 point{};


movement<float2, motion::cubic_curve> movement_down{500ms, {300.f,0.f}, {300.f,200.f}};
movement<float, back_and_forth> movement_x{2000ms, 200, 300};
movement<float, forth_and_back> movement_y{2000ms, 200, 300};


void start(Program& program)
{
	program.draw_loop = [](auto frame, auto delta)
	{

		// frame.begin_sketch()
		// 	.rectangle(rect{ frame.size })
		// 	.fill(0xffffff_rgb)
		// ;

		{ auto sketch = frame.begin_sketch();
				sketch.ellipse(rect{point_size, point, common::half});
			sketch.line_width(1).outline(0x555555_rgb);
		}

		{ auto sketch = frame.begin_sketch();
				sketch.ellipse(rect{point_size, float2{200.f,200.f}, common::half});
			sketch.line_width(1).outline(0x550000_rgb);
		}
		{ auto sketch = frame.begin_sketch();
				sketch.ellipse(rect{point_size, float2{300.f,300.f}, common::half});
			sketch.line_width(1).outline(0x005500_rgb);
		}

		// TODO: implement and use ensemble within symphony here
		if(!movement_down.done())
		{
			movement_down.move(point, delta);
		}
		else
		{
			movement_y.move(point.y(), delta);
			movement_x.move(point.x(), delta);
		}

	};
}
